package gui;

import java.awt.Color;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import model.Client;

public class PanelClient extends JPanel{
	private JLabel lblNomDuClient,
					lblPrenomDuClien,
					lblNoTel,
					lblAdresse;
	private JTextField txtFldNomClient,
						txtFldPrenomClient,
						txtFldNoTel;
	private JTextArea textAdresse;
	
	
	public PanelClient(){
		super();
		
		this.setBackground(new Color(244, 247, 252));
		this.setSize(490, 188);
		this.setLayout(null);
		
		lblNomDuClient = new JLabel("Nom du client");
		lblNomDuClient.setFont(new Font("Bookman Old Style", Font.BOLD, 12));
		lblNomDuClient.setBounds(10, 16, 118, 14);
		this.add(lblNomDuClient);
		
		txtFldNomClient = new JTextField();
		txtFldNomClient.setFont(new Font("Bookman Old Style", Font.BOLD, 12));
		txtFldNomClient.setBounds(239, 13, 132, 20);
		this.add(txtFldNomClient);
		txtFldNomClient.setColumns(20);
		
		lblPrenomDuClien = new JLabel("Prenom du clien");
		lblPrenomDuClien.setFont(new Font("Bookman Old Style", Font.BOLD, 12));
		lblPrenomDuClien.setBounds(10, 46, 128, 14);
		this.add(lblPrenomDuClien);
		
		txtFldPrenomClient = new JTextField();
		txtFldPrenomClient.setFont(new Font("Bookman Old Style", Font.BOLD, 12));
		txtFldPrenomClient.setBounds(239, 43, 132, 20);
		this.add(txtFldPrenomClient);
		txtFldPrenomClient.setColumns(10);
		
		lblNoTel = new JLabel("Numero de telephone");
		lblNoTel.setFont(new Font("Bookman Old Style", Font.BOLD, 12));
		lblNoTel.setBounds(10, 76, 151, 14);
		this.add(lblNoTel);
		
		txtFldNoTel = new JTextField();
		txtFldNoTel.setFont(new Font("Bookman Old Style", Font.BOLD, 12));
		txtFldNoTel.setBounds(239, 73, 132, 20);
		this.add(txtFldNoTel);
		txtFldNoTel.setColumns(10);
		
		lblAdresse = new JLabel("Adresse");
		lblAdresse.setFont(new Font("Bookman Old Style", Font.BOLD, 12));
		lblAdresse.setBounds(10, 103, 151, 14);
		this.add(lblAdresse);
		
		textAdresse = new JTextArea();
		textAdresse.setFont(new Font("Bookman Old Style", Font.BOLD, 12));
		textAdresse.setBounds(239, 107, 241, 68);
		this.add(textAdresse);

		setVisible(true);
	}
	
	/**
	 * Active ou desactive les zone de texte editable.
	 * @param mode si on peu editer les champs false, sinon true
	 */
	public void setConsultationMode(boolean mode){
		txtFldNomClient.setEditable(!mode);
		txtFldPrenomClient.setEditable(!mode);
		txtFldNoTel.setEditable(!mode);
		textAdresse.setEditable(!mode);
	}
	
	public void fillWithClient(Client client){
		txtFldNomClient.setText(client.getNom());
		txtFldPrenomClient.setText(client.getPrenom());
		txtFldNoTel.setText(client.getTelephone());
		textAdresse.setText(client.getAdresse());
	}
	
	public Client getInfoClient(){
		Client client = new Client();
		

		if (client.setTelephone(txtFldNoTel.getText())){
			client.setNom(txtFldNomClient.getText());
			client.setPrenom(txtFldPrenomClient.getText());
			client.setAdresse(textAdresse.getText());
		}
		else{
			client = null;
		}
		
		return client;
	}
}
